if (typeof(UI) === "undefined") {
    var UI = {};
}

// Class: UI.Batch
UI.Batch = (function () {
    var data = {
        "drawLayer": []
    };

    var execute = {
        "drawLayer": function () {
            $.each(data.drawLayer, function (index, layer) {
                layer.draw();
            });
            data.drawLayer = [];
        }
    };

    var enqueue = function (group, item) {
        if ($.inArray(item, data[group]) === -1) {
            data[group].push(item);

            // If this was the first item, schedule execution.
            if (data[group].length === 1) {
                setTimeout(execute[group], 1);
            }
        }
    };

    return {
        "drawLayer": function (layer) {
            enqueue("drawLayer", layer);
        }
    }
}());
